package com.joshua.spring.controller;

import com.joshua.spring.annotation.AroundLogger;
import com.joshua.spring.entity.vo.GlobalResponse;
import com.joshua.spring.form.ContainsArrayObjForm;
import com.joshua.spring.form.ParamsObjFrom;
import com.joshua.spring.spi.ProviderDemoClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

import static com.joshua.spring.constant.ConsumerApiConstants.Demo.*;

/**
 * description
 * package com.spring.joshua.controller
 * classname  ConsumerDemoController
 *
 * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
 * @date 2020/3/30 16:00
 */

@RestController
@RequestMapping(CONSUMER)
@Slf4j
public class ConsumerDemoController {

    @Autowired
    private ProviderDemoClient providerDemoClient;

    @AroundLogger(env = "dev")
    @GetMapping(REMOTE_PATH_INFO)
    public GlobalResponse pathInfo() {
        return providerDemoClient.pathInfo(String.valueOf(System.currentTimeMillis()));
    }

    @GetMapping(REMOTE_QUERY_OBJ)
    public GlobalResponse paramsObj() {
        ParamsObjFrom paramsObj = new ParamsObjFrom();
        paramsObj.setTotal("11");
        paramsObj.setAge("12");
        paramsObj.setName("张三");
        return providerDemoClient.paramsObj(paramsObj);
    }

    @GetMapping(REMOTE_ARRAY)
    public GlobalResponse arrayInfo() {
        String str = "helloWord";
        String[] strArray = str.split("");
        return providerDemoClient.arrayInfo(strArray);
    }

    @GetMapping(REMOTE_LIST)
    public GlobalResponse listInfo() {
        ContainsArrayObjForm form = new ContainsArrayObjForm();
        String str = "helloWord";
        String[] strArray = str.split("");
        form.setArray(strArray);
        List<String> list = Arrays.asList(str.substring(5).split(""));
        form.setList(list);
        return providerDemoClient.listInfo(form);
    }

}
